import { makeAutoObservable } from "mobx";
import type { questionType, controlLogicType, optionType } from "@/types/index";

export const modalState = makeAutoObservable({
  /**题目id*/
  id: 0,
  /**题目索引*/
  indexNum: 0,
  /**是否开启批量添加*/
  isBatch: false,
  /**选项文本*/
  optionText: "",
  /**是否显示向前关联*/
  isFront: false,
  /**是否显示复制关联*/
  isCopy: false,
  /**是否显示选项关联*/
  isOption: false,
  /**题目标题*/
  title: "",
  /**题目数据*/
  questions: [] as questionType[],
  /**控制逻辑*/
  controlLogic: undefined as controlLogicType | undefined,
  /**题目选项*/
  option: [] as optionType[],
  /**选项逻辑*/
  controlOption: [] as controlLogicType[],
  /**批量添加*/
  getBatchAdd(text: string, index: number) {
    this.optionText = text;
    this.indexNum = index;
    this.isBatch = true;
  },
  /**打开向前关联*/
  frontOpen(data: questionType[], id: number, title: string, controlLogic: controlLogicType | undefined) {
    this.questions = data;
    this.id = id;
    this.title = title;
    this.controlLogic = controlLogic;
    this.isFront = true;
  },
  /**打开复制关联*/
  copyOpen(data: questionType[], id: number, title: string, controlLogic: controlLogicType | undefined) {
    this.questions = data;
    this.id = id;
    this.title = title;
    this.controlLogic = controlLogic;
    this.isCopy = true;
  },
  /**打开选项关联*/
  optionOpen(data: questionType[], title: string, option: optionType[], id: number, controlOption: controlLogicType[]) {
    this.questions = data;
    this.title = title;
    this.option = option;
    this.id = id;
    this.controlOption = controlOption;
    this.isOption = true;
  }
});
